<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.ort">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
    <style>
        .layui-upload-img{
            border: 1px solid #1E9FFF;
            width: 200px;
            height: 200px;
            border-radius: 1px;;
        }
    </style>
</head>
<body>
<div class="layui-container" style="margin: 10px 0px; ">
    <form class="layui-form layui-form-pane">
        <input type="hidden" id="photo" name="photo">
        <div class="layui-form-item">
            <label class="layui-form-label">品牌商Id</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="brandId" name="brandId" lay-verify="required" placeholder="Id必填" autocomplete="off"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">品牌商名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="title"  name="title" lay-verify="required" placeholder="名称必填" autocomplete="off" />
            </div>
        </div>

        <div class="layui-form-item" >
            <label class="layui-form-label" style="left: auto;">品牌商图片</label>
                <div class="layui-input-inline" style="left: 140px;" >
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="po">
                    </div>
                    <a class="layui-btn layui-btn-wram" id="checkPhoto" style="width:200px" >
                        <i class="layui-icon layui-icon-add-1"></i>
                    </a>
                </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">品牌介绍</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" id="introduce" name="introduce" autocomplete="off"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">底价</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="price" name="price" autocomplete="off" />
            </div>
        </div>

        <div class="layui-form-item" >
            <div class="layui-input-block" style="display: none;">
                <a class="layui-btn" id="submitBtn" lay-submit="" lay-filter="submitBtn">提交</a>
            </div>
        </div>

    </form>
</div>
<script>
    var $;
    layui.use(['form','jquery','upload','layer'],function () {
        var form = layui.form,
            upload = layui.upload,
            layer = layui.layer;
            $ = layui.jquery;

        var photoUpload = upload.render({
            elem:'#checkPhoto',
            url:'/file/fc/fileUpload',
            before: function (obj) {
                obj.preview(function (i,f,r) {
                    $('#po').attr('src',r);
                });
            },
            done:function (res) {
                if(!res.is){
                    layer.alert('上传失败，请稍后再试......')
                }else{
                    $('#photo').val(res.file.id);
                }
            }
        })

        form.on('submit(submitBtn)',function (data){
            alert("SSS")
            var formData=data.field;
            console.log(formData)
            $.ajax({
                type: 'post',
                url:'/brand/bc/add',
                data:formData,
                dataType:'json',
                success:function (result){
                    layer.msg(result.msg);
                    if (result.is){
                        let index=parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }
                }
            })
        })
    });

    function btnSubmit(){
        $('#submitBtn').click();
    }

</script>
</body>
</html>
